package com.surfilter.msmp.web.common;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.surfilter.msmp.common.model.MDict;
import com.surfilter.msmp.common.service.MDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 字典表所有数据
 * Created by msh on 2019-11-13.
 */
@Component
public class DictMap {

    @Autowired
    private MDictService mDictService;


    public  Map<String,Map<String,String>> allDictMap(){

        //查询所有字典数据
        EntityWrapper<MDict> entityWrapper = new EntityWrapper<>();
        List<MDict> dictList = mDictService.selectList(entityWrapper);

        Map<Integer,String> mfMap = new HashMap<>();

        //将所有的数据封装到Map中、
        Map<String,Map<String,String>> dictMap = new HashMap<>();
        for(MDict mDict : dictList){
               String type = mDict.getmType(); //类型
               if(dictMap.containsKey(type)){
                   //存在则需要在子map中加入键值
                   Map<String,String> childMap = dictMap.get(type);
                   childMap.put(mDict.getmKey(),mDict.getmValue());
                   dictMap.put(type,childMap);
               }else{
                   //如果是新的类型进行新建
                   Map<String,String> childMap = new HashMap<>();
                   childMap.put(mDict.getmKey(),mDict.getmValue());
                   dictMap.put(type,childMap);
               }
        }

        return dictMap;
    }

}
